﻿using System;
using System.Collections.Generic;
using System.Text;
using Core.SimpleTemp.Common;
using Core.Toolkit.Message.Model;

namespace Core.Toolkit.Message
{
    [AutoDi(typeof(IMessage))]
    public class Message : IMessage
    {
        private readonly IEnumerable<IMessageProvider> _messageProviders;
        public Message(IEnumerable<IMessageProvider> messageProviders)
        {
            _messageProviders = messageProviders;
        }

        /// <summary>
        /// 发送一条消息
        /// </summary>
        /// <param name="messageModel"></param>
        void IMessage.SendMessage(MessageModel messageModel)
        {
            foreach (var messageProvider in _messageProviders)
            {
                var message = messageProvider.CreateMessage();
                message.SendMessage(messageModel);
            }
        }

        /// <summary>
        /// 发送消息结合
        /// </summary>
        /// <param name="messageModel"></param>
        void IMessage.SendMessage(List<MessageModel> messageModel)
        {
            foreach (var messageProvider in _messageProviders)
            {
                var message = messageProvider.CreateMessage();
                message.SendMessage(messageModel);
            }
        }
    }
}
